'use strict';

define([
	'jquery',
	'underscore',
	'backbone',
	'bootstrap',
	'backgrid',
	'backgrid-paginator'
],function(
	$,
	_,
	Backbone,
	Bootstrap,
	Backgrid,
	BackgridPaginator
){			
	var MyPaginator=Backgrid.Extension.MyPaginator=Backgrid.Extension.Paginator.extend({
				
		controls: {
		      rewind: {
		        label: "首页",
		        title: "首页"
		      },
		      back: {
		        label: "上一页",
		        title: "上一页"
		      },
		      forward: {
		        label: "下一页",
		        title: "下一页"
		      },
		      fastForward: {
		        label: "尾页",
		        title: "尾页"
		      }
		   },
		
		render: function () {
        	this.$el.empty();

	      	var totalPages = this.collection.state.totalPages;
	
	      // Don't render if collection is empty
	      if(this.renderMultiplePagesOnly && totalPages <= 1) {
	        return this;
	      }
	
	      if (this.handles) {
	        for (var i = 0, l = this.handles.length; i < l; i++) {
	          this.handles[i].remove();
	        }
	      }
	
	      var handles = this.handles = this.makeHandles();
	
		var $c = $('<div class="col-xs-4" style="padding-top: 5px;"></div>').append($('<span> 共 <b>'+ this.collection.state.totalRecords +'</b>  条</span>'));
		 
		  var $ul = $("<ul class='pagination pagination-sm pull-right'></ul>");
	      
	      for (var i = 0; i < handles.length; i++) {
	        $ul.append(handles[i].render().el);
	      }
	      
		 $ul.wrap('<div class="col-xs-8"></div>');
		 
		 
	      this.$el.append($c).append($ul);
	    
	
	      return this;
        			        
        }
	
	});

	return MyPaginator;
});
